using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class TypeofReferencedDataAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public TypeofReferencedDataAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.UserGroupNationalDefined;
						tableVersionTypes[HL7Version.v231] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v24] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v27] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{"AP","AU","FT","IM","NS","SD","SI","TX"};
						validVersionCodes[HL7Version.v231] = new string[]{"SI","NS","SD","TX","FT","IM","TEXT","SGML","AU","AP","Image","Audio","Application"};
						validVersionCodes[HL7Version.v24] = new string[]{"AP","AU","FT","IM","multipart","NS","SD","SI","TEXT","TX"};
						validVersionCodes[HL7Version.v25] = new string[]{"AP","AU","FT","IM","multipart","NS","SD","SI","TEXT","TX"};
						validVersionCodes[HL7Version.v251] = new string[]{"AP","AU","FT","IM","multipart","NS","SD","SI","TEXT","TX"};
						validVersionCodes[HL7Version.v26] = new string[]{"AP","AU","FT","IM","multipart","NS","SD","SI","TEXT","TX"};
						validVersionCodes[HL7Version.v27] = new string[]{"AP","AU","FT","IM","multipart","NS","SD","SI","TEXT","TX"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{"Other application data, typically uninterpreted binary data","Audio Data","Formatted Text","Image Data","Non-scanned Image","Scanned Document","Scanned Image","Machine Readable Text Document"};
						validVersionDescriptions[HL7Version.v231] = new string[]{"Scanned image (HL7 V2.2 only)","Non-scanned image (HL7 V2.2 only)","Scanned document (HL7 V2.2 only)","Machine readable text document (HL7 V2.2 only)","Formatted text (HL7 V2.2 only)","Image data  (new  with HL7 v 2.3)","Machine readable text document (HL7 V2.3.1 and later)","Structured Generalized Markup Language (HL7 V2.3 and later)","Audio data  (new with HL7 v 2.3)","Other application data, typically uninterpreted binary data  (new with HL7 v 2.3)","Image data  (HL7 V2.3 and later)","Audio data  (HL7 V2.3 and later)","Other application data, typically uninterpreted binary data  (HL7 V2.3 and later)"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"Other application data, typically uninterpreted binary data  (HL7 V2.3 and later)","Audio data  (HL7 V2.3 and later)","Formatted text (HL7 V2.2 only)","Image data  (HL7 V2.3 and later)","MIME multipart package","Non-scanned image (HL7 V2.2 only)","Scanned document (HL7 V2.2 only)","Scanned image (HL7 V2.2 only)","Machine readable text document (HL7 V2.3.1 and later)","Machine readable text document (HL7 V2.2 only)"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"Other application data, typically uninterpreted binary data (HL7 V2.3 and later)","Audio data (HL7 V2.3 and later)","Formatted text (HL7 V2.2 only)","Image data (HL7 V2.3 and later)","MIME multipart package","Non-scanned image (HL7 V2.2 only)","Scanned document (HL7 V2.2 only)","Scanned image (HL7 V2.2 only)","Machine readable text document (HL7 V2.3.1 and later)","Machine readable text document (HL7 V2.2 only)"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"Other application data, typically uninterpreted binary data  (HL7 V2.3 and later)","Audio data (HL7 V2.3 and later)","Formatted text (HL7 V2.2 only)","Image data (HL7 V2.3 and later)","MIME multipart package","Non-scanned image (HL7 V2.2 only)","Scanned document (HL7 V2.2 only)","Scanned image (HL7 V2.2 only)","Machine readable text document (HL7 V2.3.1 and later)","Machine readable text document (HL7 V2.2 only)"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Other application data, typically uninterpreted binary data (HL7 V2.3 and later)","Audio data (HL7 V2.3 and later)","Formatted text (HL7 V2.2 only)","Image data (HL7 V2.3 and later)","MIME multipart package","Non-scanned image (HL7 V2.2 only)","Scanned document (HL7 V2.2 only)","Scanned image (HL7 V2.2 only)","Machine readable text document (HL7 V2.3.1 and later)","Machine readable text document (HL7 V2.2 only)"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"Other application data, typically uninterpreted binary data (HL7 V2.3 and later)","Audio data (HL7 V2.3 and later)","Formatted text (HL7 V2.2 only)","Image data (HL7 V2.3 and later)","MIME multipart package","Non-scanned image (HL7 V2.2 only)","Scanned document (HL7 V2.2 only)","Scanned image (HL7 V2.2 only)","Machine readable text document (HL7 V2.3.1 and later)","Machine readable text document (HL7 V2.2 only)"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
